/**
 * @name 基础信息请求
 */
import http from "@/utils/http";
import authMenuList from "@/routers/menuList.json";
import { Login } from "@/interface/app";

export const getAuthMenuListApi = () => {
  return authMenuList;
};

// 用户登录
export const loginApi = (params: Login.ReqLoginForm) => {
  return { data: APP_CONFIG.userInfo };
};

//获取用户信息
export const getUserInfo = () => {
  return http.get("/user/getMySessionInfo", {}, { loading: false, serverName: APP_CONFIG.ocpServer });
};

//获取用户角色
export const getUserRole = () => {
  return http.get("/user/getUserRole", {}, { loading: false, serverName: APP_CONFIG.ocpServer });
};

//获取json文件数据
export const getJsonData = (url: string) => {
  return http.getJson(
    url,
    {},
    { serverName: APP_CONFIG.assetsUrl, loading: false, headers: { "Content-Type": "application/json;charset=utf-8" } },
  );
};

/**
 * 公共模板api请求
 * @param code t_module的code
 * @param params {where:[], select:[],orderItems:[],...}
 * @param loading
 * @returns
 */
export const commonTmplApi = (code: string, params: any, loading = false) => {
  return http.post(`/app/normalQuery/tmQueryData/${code}`, params, { loading: loading });
};

/**
 * 公共模板分页查询
 * @param code t_module的code
 * @param params {where:[], select:[],orderItems:[],...}
 * @param loading
 * @returns
 */
export const commonTmplPageQuery = (code: string, params: any, loading = true) => {
  return http.post(`/app/normalQuery/tmPageQuery/${code}`, params, { loading: loading });
};

/**
 * 公共表api请求
 * @param code t_module的code
 * @param params {where:[], select:[],orderItems:[],...}
 * 如：where:[{type: "COLUMN", column: "levelNo", value: [1, 2],operator: ApiOperatorEnum}]
 * 如：orderItems:[type: "ASC", column: "mofDivCode"]
 * @param loading
 * @returns
 */
export const commonApi = (code: string, params: any, loading = true) => {
  const requestType = params.pageSize ? "pageQuery" : "queryData";
  return http.post(`/app/normalQuery/${requestType}/${code}`, params, { loading: loading });
};

/**
 * 导出
 * @param code
 * @param params
 * @param loading
 * @returns
 */
export const commonTmplExport = (code: string, params: any, loading = true) => {
  return http.download(`/app/normalExport/exportExcel/${code}`, params, { loading: loading });
};
